package edu.umn.cs5115.scheduler.entities;

import edu.umn.cs5115.scheduler.SchedulerDocument;
import edu.umn.cs5115.scheduler.framework.ManagedData;
import edu.umn.cs5115.scheduler.framework.ManagedSet;
import java.util.Set;

/**
 * This class represents a users schedule.  Currently, it just stores a set of
 * courses.
 */
public class Schedule extends ManagedData
{
    /** The key for notifications of changes to the courses in the document. */
    public static final String COURSES_KEY = "courses";
    /** The set containing the courses in the user's schedule. */    
    private ManagedSet courses;
    
    public Schedule(SchedulerDocument document)
    {
        super(document);
        // disable undo registration - we don't want our initialization to be undone!
        document.getUndoManager().disableUndoRegistration();
        courses = new ManagedSet(document);
        //courses.addAll(CourseFactory.getAllCourses(document));
        setValueForKey(COURSES_KEY, courses);
        document.getUndoManager().enableUndoRegistration();
    }
    
    /** 
     * Returns a list of courses.  You may add or remove courses directly using
     * this set, or use addCourse and removeCourse instead.
     * @return The set of courses in this schedule.
     * @see #addCourse(Course)
     * @see #removeCourse(Course)
     */
    public Set getCourses()
    {
        return courses;
    }
    
    /**
     * Add a course to the schedule.
     * @param courseToAdd The new course.  It is added if it is not already
     * in the schedule.
     * @see #getCourses()
     */
    public void addCourse(Course courseToAdd)
    {
        courses.add(courseToAdd);
    }
    
    /**
     * Remove a course from the schedule.
     * @param courseToRemove The course to remove.  It is removed if it is in
     * the schedule.
     * @see #getCourses()
     */
    public void removeCourse(Course courseToRemove)
    {
        courses.remove(courseToRemove);
    }
}
